package com.accp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.accp.dao.CommentsDao;
import com.accp.dao.HotevensDao;
import com.accp.entity.Comments;
import com.accp.entity.Hotevents;
import com.accp.service.CommentsService;
import com.accp.service.HotevensService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Service
public class HotevensServiceImpl implements HotevensService {
	@Autowired
	private HotevensDao hotdao;
	
	@Autowired
	private CommentsService comservice;
	
	@Override
	@Transactional
	public IPage findAll(int PageNum, int PageSize,String keyWord) {
		// TODO Auto-generated method stub
		Page page = new Page<>(PageNum, PageSize);
		QueryWrapper<Hotevents> qu = new QueryWrapper<Hotevents>();
		if(keyWord != null && keyWord != ""){ 
			System.out.println("1");
			qu.like("keyWord",keyWord);
		}
		qu.orderByDesc("searchSum");
		return hotdao.selectPage(page, qu);
	}

	@Override
	public Hotevents findbyId(int id) {
		// TODO Auto-generated method stub
		return hotdao.selectById(id);
	}

	@Override
	public Hotevents fetchEvent(int id) {
		// TODO Auto-generated method stub
		Hotevents event = hotdao.selectById(id);
		if(event == null){
			return null;
		}
		event.setComments(comservice.findAll(event.getId()));
		return event;
	}
		
}
